import os
import shutil
from utils import ReadXml
from tqdm import tqdm


SrcDir = r"I:\ImgOutput\RoadTest"
DstDir = r"I:\ImgOutput\RoadTest2"
Method = 'copy'  # move or copyfile
MoveLabel = ['AmericaLimit']


AlreadyMove = []

for root, dirs, files in os.walk(SrcDir):
    for file in tqdm(files):
        if file[-1] == 'l':
            Locations = ReadXml(root + "\\" + file)
            for Location in Locations:
                if Location[-1] in MoveLabel:
                    if Method == "move":
                        shutil.move(root + "\\" + file, DstDir + "\\" + file)
                        shutil.move(root + "\\" + file[:-3] + "jpg", DstDir + "\\" + file[:-3] + "jpg")
                    elif Method == "copy":
                        # shutil.copyfile(root + "\\" + file, DstDir + "\\" + file)
                        shutil.copyfile(root + "\\" + file[:-3] + "jpg", DstDir + "\\" + file[:-3] + "jpg")
                    AlreadyMove.append(file)
                    break
print("%d xmls and jpgs have been deal" % len(AlreadyMove))
print(AlreadyMove)
